package en.edu.zucc.pb.loginapplication.db;

import android.content.Context;

//import com.example.moments.App;
//import com.example.moments.db.AppDatabase;

import en.edu.zucc.pb.loginapplication.AppDatabase;
import en.edu.zucc.pb.loginapplication.repository.RecordRepository;
import en.edu.zucc.pb.loginapplication.repository.UserRepository;
import lombok.Data;

@Data
public class Repository {
//    public  static ContentDao contentDao;
//    public  static  CommentDao commentDao;
//    public  static  ImageDao imageDao;
//    public  static  LikeDao likeDao;
//    public  static  LinkDao linkDao;

//    dao 貌似不应该在这里 定义了
//    private ContentDao contentDao;
//    private CommentDao commentDao;
//    private ImageDao imageDao;
//    private LikeDao likeDao;
//    private LinkDao linkDao;

    Context context;

    AppDatabase database;

//    CommentRepository commentRepository;
//    ContentRepository contentRepository;
//    ImageRepository imageRepository;
//    LikeRepository likeRepository;
//    LinkRepository linkRepository;
    RecordRepository recordRepository;
    UserRepository userRepository;

//    CommentRepository commentRepository;
//    CommentRepository commentRepository;
//    CommentRepository commentRepository;


    public Repository(Context context) {
        this.context = context;
        initDatabase(context);
    }

//    public Repository() {
//        initDatabase();
////        不会实例化
////        Repository.commentDao
////        Repository.ge
////        Repository repository=new Repository();
////        repository.getCommentDao().getAll()
//    }

    void initDao(){
//        这个好像不是在这里
//        if (contentDao == null) {
//            contentDao = database.contentDao();
//        }
//        if (commentDao == null) {
//            commentDao = database.commentDao();
//        }
//        if (imageDao == null) {
//            imageDao = database.imageDao();
//        }
//        if (likeDao == null) {
//            likeDao = database.likeDao();
//        }
//        if (linkDao == null) {
//            linkDao = database.linkDao();
//        }

    }
//    void initDatabase() {
//        Context context = App.getContext();
//        initDatabase(context);
//    }

    void initDatabase(Context context) {
//        Context context = App.getContext();
//        database = AppDatabase.getDatabase(getApplicationContext());
        if (database == null) {
            database = AppDatabase.getDatabase(context);
        }

//        CommentRepository commentRepository;
//        ContentRepository contentRepository;
//        ImageRepository imageRepository;
//        LikeRepository likeRepository;
//        LinkRepository linkRepository;
        if(recordRepository==null){
            recordRepository  =new RecordRepository(database.recordDao());
        }
        if(userRepository==null){
            userRepository  =new UserRepository(database.userDao());
        }

//        if(commentRepository==null){
//            commentRepository  =new CommentRepository(database.commentDao());
//        }
//        if(contentRepository==null){
//            contentRepository  =new ContentRepository(database.contentDao());
//        }
//        if(imageRepository==null){
//            imageRepository  =new ImageRepository(database.imageDao());
//        }
//        if(likeRepository==null){
//            likeRepository  =new LikeRepository(database.likeDao());
//        }
//        if(linkRepository==null){
//            linkRepository  =new LinkRepository(database.linkDao());
//        }


//        if(commentRepository==null){
//            commentRepository  =new CommentRepository(database.commentDao());
//        }
//        if(commentRepository==null){
//            commentRepository  =new CommentRepository(database.commentDao());
//        }
//        if(commentRepository==null){
//            commentRepository  =new CommentRepository(database.commentDao());
//        }
//        if(commentRepository==null){
//            commentRepository  =new CommentRepository(database.commentDao());
//        }
//        if(commentRepository==null){
//            commentRepository  =new CommentRepository(database.commentDao());
//        }
//        if(commentRepository==null){
//            commentRepository  =new CommentRepository(database.commentDao());
//        }

//        commentRepository=  commentRepository==null?
//                new CommentRepository(database.commentDao()):commentRepository;

//         public abstract ImageDao imageDao();
//         public abstract LikeDao likeDao();
//         public abstract LinkDao linkDao();
//        数据库必然建立在 activity 之上吗
//        contentDao = database.contentDao();
//        commentDao = database.commentDao();
//        Content content = new Content();
//        contentDao.insert()
    }
}
